library(ggplot2)
library(plotly)
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
msleep
cat(factor(msleep$order))
3 15 17 19 2 14 3 17 3 2 2 17 15 17 19 17 19 6 10 7 16 5 13 13 9 15 17 3 15 2 4 3 10 15 15 16 7 15 17 17 17 17 5 17 15 17 17 11 2 15 3 3 3 15 9 15 17 8 3 4 8 6 10 17 17 15 19 17 17 17 17 17 19 2 12 17 13 1 18 4 3 3 3
df_order = data.frame(table(msleep$order))
print(df_order)
fig_order = plot_ly(type='pie', labels=df_order$Var1, values=df_order$Freq,
textinfo='label+percent',insidetextorientation='radial')
fig_order
df_vore = data.frame(table(msleep$vore))
df_vore
fig_vore = plot_ly(type='pie', labels=df_vore$Var1, values=df_vore$Freq,
textinfo='label+percent',insidetextorientation='radial')
fig_vore
fig_sp = plot_ly(data = msleep, x=~brainwt, y=~bodywt, color = ~order)
fig_sp
No trace type specified:
Based on info supplied, a 'scatter' trace seems appropriate.
Read more about this trace type -> https://plotly.com/r/reference/#scatter
No scatter mode specifed:
Setting the mode to markers
Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
Warning: Ignoring 27 observations
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
No trace type specified:
Based on info supplied, a 'scatter' trace seems appropriate.
Read more about this trace type -> https://plotly.com/r/reference/#scatter
No scatter mode specifed:
Setting the mode to markers
Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
Warning: Ignoring 27 observations
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
plot(sqrt(msleep$bodywt), sqrt(msleep$brainwt), col="red")
text(sqrt(msleep$bodywt), sqrt(msleep$brainwt), msleep$name, cex=0.5)
plot(msleep$bodywt^(1/100), msleep$brainwt^(1/100), col="red")
text(msleep$bodywt^(1/100), msleep$brainwt^(1/100), msleep$name, cex=0.5)
plot(log10(msleep$bodywt), log10(msleep$brainwt), col="red")
text(log10(msleep$bodywt), log10(msleep$brainwt), msleep$name, cex=0.5)
t <- list(family = "Helvetica",size = 14,color = "blue")
t1 <- list(family = "Times New Roman",color = "red")
t2 <- list(family = "Courier New",size = 14,color = "green")
t3 <- list(family = 'Arial')
fig_sp = plot_ly(data = msleep, x = ~log10(bodywt), y = ~log10(brainwt), color = ~name,
type = 'scatter', mode = 'markers')%>%
layout(title= list(text = "Body weight vs Brain weight",font = t1), font=t,
legend = list(title=list(text='Animals',font = t2)),
xaxis = list(title = list(text ='Brain Weight', font = t3)),
yaxis = list(title = list(text ='Body Weight', font = t3)),
plot_bgcolor='#e5ecf6')
fig_sp
Warning: Ignoring 27 observations
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning: Ignoring 27 observations
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
This is shows a clear linear relation-ship between Body weight and Brain weight
# Define labels for the bars
labs = c('herbi'='Herbivore',
'carni'='Carnivore',
'omni'='Omnivore',
'insecti'='Insectivore')
bar_plot = ggplot(data=msleep, aes(x = vore, y = ..count.. / sum(..count..),fill = factor(vore))) +
geom_bar(color='black') +
labs(x = "Vore", y = "Percentage of Vore", title = "Percentage of the quality of the Vore") +
scale_x_discrete(labels =labs)
scale_y_continuous(labels = scales::percent)
<ScaleContinuousPosition>
Range:
Limits: 0 -- 1
ggplotly(bar_plot)
histogram_plot = ggplot(data=msleep, aes(x = sleep_total)) +
geom_histogram(binwidth = 1.25, color = "black",fill = "grey") +
labs(x = "Total Time asleep per day(h)", y="Count", title="Count of Total Time asleep per day(h)") +
scale_x_discrete(labels =labs)
ggplotly(histogram_plot)
NA
density_plot = ggplot(data=msleep, aes(x =log10(brainwt))) +
geom_density(fill = "indianred3") +
labs(x = "brain weight", y="density", title="Kernal density of the brain weight")
ggplotly(density_plot)
Warning: Removed 27 rows containing non-finite values (stat_density).